﻿#region

using System;

#endregion

namespace iTunesArtworkApp.Core
{
    /// <summary>
    /// iTunes Artwork Manager is responsible for managing the updating of artwork of 
    /// ITunes Albums.
    /// </summary>
    public class iTunesArtworkManager
    {
        private readonly IiTunesWrapper _itunesService;
        private readonly IArtworkService _artworkService;

        /// <summary>
        /// Initializes a new instance of the <see cref="iTunesArtworkManager"/> class.
        /// </summary>
        /// <param name="itunesService">The itunes service.</param>
        /// <param name="artworkService">The artwork service.</param>
        public iTunesArtworkManager(IiTunesWrapper itunesService, IArtworkService artworkService)
        {
            if (itunesService == null) throw new ArgumentNullException("itunesService");
            if (artworkService == null) throw new ArgumentNullException("artworkService");
            _itunesService = itunesService;
            _artworkService = artworkService;

            
        }

        /// <summary>
        /// Populates the missing artwork.
        /// </summary>
        public void PopulateMissingArtwork()
        {
            var albums = _itunesService.GetAlbums();

            foreach (var album in albums)
            {
                if (album == null) 
                    continue;

                var albumToUpdate = album;
                _artworkService.GetArtwork(ref albumToUpdate);
                _itunesService.UpdateArtwork(ref albumToUpdate);
            }

               
        }
    } // end class
}